<template>
  <div
    class="banner"
    :style="{
      backgroundColor: config.pageConfig.color,
    }"
  >
    <div
      class="tabs"
      :style="{
        backgroundColor: config.pageConfig.tabColor,
        marginTop: config.pageConfig.tabMarginTop + 'px',
        marginBottom: config.pageConfig.tabMarginBottom + 'px',
        marginLeft: config.pageConfig.tabMargin + 'px',
        marginRight: config.pageConfig.tabMargin + 'px',
        borderTopLeftRadius: config.pageConfig.bgRadiusTop + 'px',
        borderTopRightRadius: config.pageConfig.bgRadiusTop + 'px',
        borderBottomLeftRadius: config.pageConfig.bgRadiusBottom + 'px',
        borderBottomRightRadius: config.pageConfig.bgRadiusBottom + 'px',
      }"
    >
      <div
        v-for="(item, index) in config.pageConfig.tabList"
        :key="index"
        @click="chooseIndex(index)"
        :style="{
          marginLeft: config.pageConfig.tabDistance + 'px',
          marginRight: config.pageConfig.tabDistance + 'px',
          borderColor:
            config.pageConfig.tabShow && currentIndex == index
              ? config.pageConfig.tablineColor
              : 'transparent',
        }"
      >
        <div
          :style="{
            borderColor:
              config.pageConfig.tabShow && currentIndex == index
                ? config.pageConfig.tablineColor
                : 'transparent',
          }"
        >
          <h4
            :style="{
              color:
                currentIndex == index
                  ? config.pageConfig.selectedcolor
                  : config.pageConfig.unselectcolor,
            }"
          >
            {{ item.title }}
          </h4>
          <p
            v-if="config.pageConfig.subShow"
            :style="{
              color:
                currentIndex == index
                  ? config.pageConfig.selectedsubColor
                  : config.pageConfig.unsubColor,
            }"
          >
            {{ item.subtitle }}
          </p>
        </div>
      </div>
    </div>
    <div
      :style="{
        marginTop: config.pageConfig.marginTop + 'px',
        marginBottom: config.pageConfig.marginBottom + 'px',
        marginLeft: config.pageConfig.margin + 'px',
        marginRight: config.pageConfig.margin + 'px',
      }"
      :class="`goods-${config.pageConfig.custom}`"
    >
      <div
        v-for="(item, idx) in config.pageConfig.tabList[currentIndex].goodsList"
        :key="idx"
        class="content-list"
        :style="
          config.pageConfig.custom == '3' || config.pageConfig.custom == '4'
            ? {
                width: `calc(50% - ${config.pageConfig.distance}px)`,
                margin: `${config.pageConfig.distance / 2}px`,
              }
            : config.pageConfig.custom == '5' ||
              config.pageConfig.custom == '6' ||
              config.pageConfig.custom == '7'
            ? {
                width: `calc(33.3% - ${config.pageConfig.distance}px)`,
                margin: `${config.pageConfig.distance / 3}px`,
              }
            : {
                marginBottom: config.pageConfig.distance + 'px',
              }
        "
      >
        <div
          :style="{
            borderTopLeftRadius: config.pageConfig.radiusTop + 'px',
            borderTopRightRadius: config.pageConfig.radiusTop + 'px',
            borderBottomLeftRadius: config.pageConfig.radiusBottom + 'px',
            borderBottomRightRadius: config.pageConfig.radiusBottom + 'px',
            borderColor: config.pageConfig.borderColor,
            backgroundColor: config.pageConfig.goodsColor,
          }"
        >
          <div
            class="goods-label"
            :class="
              config.pageConfig.dotStyle == 1
                ? 'goods-icon1'
                : config.pageConfig.dotStyle == 2
                ? 'goods-icon2'
                : 'goods-icon3'
            "
            v-if="config.pageConfig.dotSetting == 2"
          >
            {{ config.pageConfig.dotName }}
          </div>
          <div class="goods-label" v-if="config.pageConfig.dotSetting == 3">
            <img
              :src="config.pageConfig.dotUrl"
              v-if="config.pageConfig.dotUrl"
              alt=""
            />
            <img v-else src="../../../../../../assets/app/bar/default_banner.png" alt="" />
          </div>
          <img
            :style="{
              borderTopLeftRadius: config.pageConfig.radiusTop + 'px',
              borderTopRightRadius: config.pageConfig.radiusTop + 'px',
              borderBottomLeftRadius: config.pageConfig.radiusBottom + 'px',
              borderBottomRightRadius: config.pageConfig.radiusBottom + 'px',
            }"
            v-if="item.imgUrl"
            :src="item.imgUrl"
            class="banner-img"
            alt=""
          />

          <img
            :style="{
              borderTopLeftRadius: config.pageConfig.radiusTop + 'px',
              borderTopRightRadius: config.pageConfig.radiusTop + 'px',
              borderBottomLeftRadius: config.pageConfig.radiusBottom + 'px',
              borderBottomRightRadius: config.pageConfig.radiusBottom + 'px',
            }"
            v-else
            src="../../../../../../assets/app/bar/default_banner.png"
            class="banner-img"
            alt=""
          />
          <div class="goods-detail">
            <h4
              v-if="config.pageConfig.titleShow"
              :style="{
                color: config.pageConfig.titlecolor,
              }"
            >
              {{ item.title }}
            </h4>
            <p
              class="subtitle"
              v-if="
                config.pageConfig.subtitleShow &&
                (config.pageConfig.custom == '1' ||
                  config.pageConfig.custom == '2' ||
                  config.pageConfig.custom == '3')
              "
              :style="{
                color: config.pageConfig.subtitlecolor,
              }"
            >
              {{ item.subtitle }}
            </p>
            <p
              class="salenum"
              v-if="
                config.pageConfig.salenumShow &&
                (config.pageConfig.custom == '1' ||
                  config.pageConfig.custom == '2' ||
                  config.pageConfig.custom == '3')
              "
              :style="{
                color: config.pageConfig.salenum,
              }"
            >
              已售{{ item.salenum }}
            </p>
            <div>
              <p
                v-if="config.pageConfig.priceShow"
                :style="{
                  color: config.pageConfig.price,
                }"
              >
                ￥{{ item.price }}.00<span
                  v-if="
                    config.pageConfig.delpriceShow &&
                    (config.pageConfig.custom == '1' ||
                      config.pageConfig.custom == '2' ||
                      config.pageConfig.custom == '3')
                  "
                  :style="{
                    color: config.pageConfig.delprice,
                  }"
                  >￥{{ item.delPrice }}.00</span
                >
              </p>
              <p v-if="config.pageConfig.custom != '4'" class="purchase">
                <span
                  v-if="
                    config.pageConfig.custom == '1' ||
                    config.pageConfig.custom == '2' ||
                    config.pageConfig.custom == '3'
                  "
                  >购买</span
                >
                <el-icon v-else><CirclePlusFilled /></el-icon>
              </p>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script lang="ts">
export default {
  name: "Image",
};
</script>
<script lang="ts" setup>
import { reactive, onMounted } from "vue";
const config = defineProps({
  pageConfig: {
    type: Object,
    default: {
      bgcolor: "transparent",
      tabColor: "#fff",
      unselectcolor: "#666",
      selectedcolor: "#ef4f4f",
      tabShow: true,
      tablineColor: "#ef4f4f",
      subShow: false,
      unsubColor: "#666",
      selectedsubColor: "#666",
      selectBg: "1",
      selectBgColor: "transparent",
      selectBgUrl: "",
      tabDistance: 20,
      tabMarginTop: 0,
      tabMarginBottom: 0,
      tabMargin: 0,
      tabIndex: 0,
      bgRadiusTop: 0,
      bgRadiusBottom: 0,
      style: "1",
      borderWidth: 1,
      borderColor: "#ededed",
      custom: "1",
      goodsColor: "#fff",
      titlecolor: "#3d404d",
      titleShow: true,
      subtitlecolor: "#999ca7",
      subtitleShow: true,
      priceShow: true,
      price: "#fd463e",
      delpriceShow: true,
      delprice: "#999CA7",
      salenumShow: true,
      salenum: "#999CA7",
      carUrl: "",
      dotSetting: "1",
      dotStyle: "1",
      dotName: "",
      dotUrl: "",
      distance: 7,
      marginTop: 12,
      marginBottom: 12,
      margin: 12,
      radiusTop: 4,
      radiusBottom: 4,
      tabList: [
        {
          title: "选项",
          subtitle: "副标题",
          goodsList: [],
        },
        {
          title: "选项",
          subtitle: "副标题",
          goodsList: [],
        },
      ],
    },
  },
});
const contentList = ref([
  {
    id: "",
    title: "杯子男家用马克杯瓷杯陶瓷女创意个性北欧办公室喝水杯早餐杯",
    subtitle: "杯子男家用马克杯瓷杯陶瓷女创意个性北欧办公室喝水杯早餐杯",
    price: "99",
    delPrice: "129",
    salenum: "0",
    imgUrl: "",
    name: "",
    url: "",
  },
  {
    id: "",
    title: "杯子男家用马克杯瓷杯陶瓷女创意个性北欧办公室喝水杯早餐杯",
    subtitle: "杯子男家用马克杯瓷杯陶瓷女创意个性北欧办公室喝水杯早餐杯",
    price: "99",
    delPrice: "129",
    salenum: "",
    imgUrl: "",
    name: "",
    url: "",
  },
  {
    id: "",
    title: "杯子男家用马克杯瓷杯陶瓷女创意个性北欧办公室喝水杯早餐杯",
    subtitle: "杯子男家用马克杯瓷杯陶瓷女创意个性北欧办公室喝水杯早餐杯",
    price: "99",
    delPrice: "129",
    salenum: "",
    imgUrl: "",
    name: "",
    url: "",
  },
]);
let emits = defineEmits<{ (e: "close", flag: boolean): void }>();
const currentIndex = ref(0);
const chooseIndex = (idx: number) => {
  currentIndex.value = idx;
};
</script>
<style lang="scss" scoped>
.banner {
  width: 100%;
  overflow: hidden;
  .tabs {
    width: 100%;
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    overflow-x: auto;
    > div {
      flex: 1;
      text-align: center;
      min-width: 48px !important;
      font-size: 14px;
      div {
        float: left;
        border-bottom: 2px solid transparent;
        h4 {
          height: 40px;
          line-height: 40px;
        }
        p {
          height: 20px;
          line-height: 20px;
        }
      }
    }
  }
  .content-list {
    > div {
      position: relative;
      .goods-label {
        position: absolute;
        z-index: 10;
        color: #fff;
        font-size: 22px;
        transform: scale(0.5);
        transform-origin: top left;
        &.goods-icon1 {
          width: 60px;
          height: 60px;
          background: url(@/assets/app/other/goods/hotbg-1.png);
          background-size: 60px;
          line-height: 44px;
          text-align: center;
        }
        &.goods-icon2 {
          width: 52px;
          height: 56px;
          background: url(@/assets/app/other/goods/hotbg-2.png);
          background-size: 52px 56px;
          line-height: 44px;
          text-align: center;
        }
        &.goods-icon3 {
          width: 64px;
          height: 44px;
          background: url(@/assets/app/other/goods/hotbg-3.png);
          background-size: 64px 44px;
          line-height: 44px;
          text-align: center;
        }
        img {
          width: 76px;
          height: 76px;
        }
      }
    }
  }
}
.goods-detail {
  position: relative;
  overflow: hidden;
  padding: 8px 12px;
  box-sizing: border-box;
  h4 {
    font-size: 14px;
    line-height: 18px;
    max-height: 36px;
    margin-bottom: 4px;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
  }
  .subtitle {
    font-size: 12px;
    height: 16px;
    line-height: 16px;
    width: 100%;
    color: #999ca7;
    margin-bottom: 4px;
    overflow: hidden;
    word-break: break-all;
    text-overflow: ellipsis;
  }
  .salenum {
    font-size: 13px;
    line-height: 18px;
    margin-bottom: 6px;
  }
  div {
    display: flex;
    align-items: center;
    justify-content: space-between;
    p {
      font-size: 14px;
      overflow: hidden;
      text-overflow: ellipsis;
      font-weight: 700;
      span {
        font-size: 12px;
        height: 13px;
        line-height: 13px;
        color: #999ca7;
        text-decoration: line-through;
      }
    }
  }
}
.goods-1 {
  > div {
    &:first-of-type {
      padding-top: 0;
    }
    div {
      position: relative;
      overflow: hidden;
      box-sizing: border-box;
      img {
        width: 100%;
      }
      .goods-detail {
        padding: 10px 12px 12px;
        h4 {
          max-height: 44px;
          font-size: 16px;
          line-height: 22px;
          font-weight: 700;
          margin-bottom: 6px;
        }
        .subtitle {
          font-size: 14px;
          height: 20px;
          line-height: 20rpx;
          overflow: hidden;
          white-space: nowrap;
          text-overflow: ellipsis;
        }
        .purchase {
          z-index: 2;
          padding: 4px 8px;
          border: 1px solid #f55;
          background: #f55;
          color: #fff;
          font-size: 12px;
          font-weight: 700;
          display: flex;
          align-items: center;
          span {
            color: #fff;
            line-height: 1;
            text-decoration: initial;
          }
        }
        .salenum {
          font-size: 13px;
          line-height: 18px;
          margin-bottom: 6px;
        }
        div {
          p {
            font-size: 18px;
            line-height: 18px;
            span {
              font-size: 14px;
              line-height: 24px;
              align-self: flex-end;
            }
          }
        }
      }
    }
  }
}

.goods-2 {
  > div {
    display: block;
    overflow: hidden;
    div {
      display: flex;
      img {
        width: 130px;
        height: 130px;
      }
      .goods-detail {
        display: block;
        .purchase {
          z-index: 2;
          padding: 4px 8px;
          border: 1px solid #f55;
          background: #f55;
          color: #fff;
          font-size: 12px;
          font-weight: 700;
          display: flex;
          align-items: center;
          span {
            color: #fff;
            line-height: 1;
            text-decoration: initial;
          }
        }
      }
    }
  }
}

.goods-3 {
  display: flex;
  flex-wrap: wrap;
  > div {
    img {
      width: 100%;
    }
    .goods-detail {
      h4 {
        height: 40px;
        max-height: 40px;
        font-size: 15px;
        line-height: 20px;
        font-weight: 700;
        margin-bottom: 6px;
      }
      > div {
        p {
          span {
            display: block;
          }
        }
      }
      .purchase {
        z-index: 2;
        padding: 4px 8px;
        border: 1px solid #f55;
        background: #f55;
        color: #fff;
        font-size: 12px;
        font-weight: 700;
        display: flex;
        align-items: center;
        span {
          color: #fff;
          line-height: 1;
          text-decoration: initial;
        }
      }
    }
  }
}

.goods-4 {
  display: flex;
  flex-wrap: wrap;
  > div {
    img {
      width: 100%;
    }
    .goods-detail {
      h4 {
        height: 40px;
        max-height: 40px;
        font-size: 15px;
        line-height: 20px;
        font-weight: 400;
        margin-bottom: 6px;
      }
    }
  }
}
.goods-5 {
  display: flex;
  flex-wrap: wrap;
  > div {
    img {
      width: 100%;
    }
    .goods-detail {
      h4 {
        height: 40px;
        max-height: 40px;
        font-size: 15px;
        line-height: 20px;
        font-weight: 400;
        margin-bottom: 6px;
      }
      .purchase {
        z-index: 2;
        color: #f55;
        font-size: 15px;
        font-weight: 700;
        display: flex;
        align-items: center;
      }
      > div {
        p {
          span {
            display: block;
          }
        }
      }
    }
  }
}

.goods-6 {
  display: flex;
  flex-wrap: nowrap;
  > div {
    &:nth-of-type(2n-1) {
      .goods-detail {
        h4 {
          height: 40px;
          max-height: 40px;
          font-size: 15px;
          line-height: 20px;
          font-weight: 400;
          margin-bottom: 6px;
        }
        > div {
          display: none;
        }
      }
    }
    &:nth-of-type(2n) {
      .goods-detail {
        h4 {
          height: 40px;
          max-height: 40px;
          font-size: 15px;
          line-height: 20px;
          font-weight: 400;
          margin-bottom: 6px;
        }
        > div {
          display: flex;
        }
      }
    }
    img {
      width: 100%;
    }
    .purchase {
      z-index: 2;
      color: #f55;
      font-size: 15px;
      font-weight: 700;
      display: flex;
      align-items: center;
    }
  }
}

.goods-7 {
  display: flex;
  flex-wrap: nowrap;
  img {
    width: 100%;
  }
  h4 {
    height: 40px;
    max-height: 40px;
    font-size: 15px;
    line-height: 20px;
    font-weight: 400;
    margin-bottom: 6px;
  }
  .purchase {
    z-index: 2;
    color: #f55;
    font-size: 15px;
    font-weight: 700;
    display: flex;
    align-items: center;
  }
}
</style>
